#include <catch2/catch.hpp>

#include <algorithm>

#include "solution.hpp"

TEST_CASE("031_next_permutation", "[031]") {
    CHECK(Solution().nextPermutationNoInplace({1,2,3}) == std::vector{1,3,2});
    CHECK(Solution().nextPermutationNoInplace({3,2,1}) == std::vector{1,2,3});
    CHECK(Solution().nextPermutationNoInplace({1,1,5}) == std::vector{1,5,1});
    CHECK(Solution().nextPermutationNoInplace({1})     == std::vector{1});

    auto perm = std::vector{1,4,2,3,5};
    auto perm_std = perm;

    std::next_permutation(perm_std.begin(), perm_std.end());
    CHECK(Solution().nextPermutationWithReturn(perm) == perm_std);

    std::next_permutation(perm_std.begin(), perm_std.end());
    CHECK(Solution().nextPermutationWithReturn(perm) == perm_std);

    std::next_permutation(perm_std.begin(), perm_std.end());
    CHECK(Solution().nextPermutationWithReturn(perm) == perm_std);

    std::next_permutation(perm_std.begin(), perm_std.end());
    CHECK(Solution().nextPermutationWithReturn(perm) == perm_std);

    std::next_permutation(perm_std.begin(), perm_std.end());
    CHECK(Solution().nextPermutationWithReturn(perm) == perm_std);

    std::next_permutation(perm_std.begin(), perm_std.end());
    CHECK(Solution().nextPermutationWithReturn(perm) == perm_std);

    perm = std::vector{1,6,4,5,3,2};
    perm_std = perm;

    std::next_permutation(perm_std.begin(), perm_std.end());
    CHECK(Solution().nextPermutationWithReturn(perm) == perm_std);

    std::next_permutation(perm_std.begin(), perm_std.end());
    CHECK(Solution().nextPermutationWithReturn(perm) == perm_std);

    perm = std::vector{6,4,1,5,3,2,2,0};
    perm_std = perm;

    std::next_permutation(perm_std.begin(), perm_std.end());
    CHECK(Solution().nextPermutationWithReturn(perm) == perm_std);

    perm = std::vector{1,5,1};
    perm_std = perm;

    std::next_permutation(perm_std.begin(), perm_std.end());
    CHECK(Solution().nextPermutationWithReturn(perm) == perm_std);
}
